﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WAD.Model;

namespace WAD.DAL.Admin
{
    public  class article : DAO
    {
 
        /// <summary>
        /// 获取一个实体对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static PageData GetArticlelist(int pageIndex, int pageSize, MArticle m, string fields)
        {
            StringBuilder sb = new StringBuilder();
            if (m.state != null && m.state >= 0)
                sb.Append("[state] = " + m.state.Value);
            else
                sb.Append("[state] = 1");
            if (m.channel_id != 0)
            {
                //按频道id过滤
                sb.Append(" and isnull(channel_id,'')='' ");
            }

            if (m.user_id != 0)
            {
                sb.Append(" and [user_id] = ").Append(m.user_id);
            }

            //if (m.is_pass != null)
            //{
            //    sb.AppendFormat(" and is_pass={0}", m.is_pass.Value ? "1" : "0");
            //}

            if (!string.IsNullOrEmpty(m.title))
                sb.AppendFormat(" and title like '%{0}%'", m.title);

            if (!String.IsNullOrEmpty(m.key_word))
            {
                sb.AppendFormat(" and (key_word like '%{0}%' OR content like '%{0}%')", m.key_word);
            }
            String where = sb.ToString();
            String orderBy = "id desc";
            String tableName = "article";
            return GetPageList(fields, orderBy, pageIndex, pageSize, where, tableName);
        }

        public static bool UpdateArtcha( string  id, int channe)
        {
            String sql = "update article set channel_id=" + channe + " where id in(" + id + ")";        
            return ExecuteNonQuery(sql) > 0;
        }
    }
}
